package com.gzfs.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCTools {
    private  static DataSource dataSource;
    static {
        dataSource = new ComboPooledDataSource("testc3p0");
    }
    public static Connection getConnection(){

        Connection connection =null;

        try {
            connection = dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return connection;
    }
    public  static  void release(Connection connection, Statement statement, ResultSet resultSet)
    {
        try {
            if(connection !=null)
            {
                connection.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        try {
            if(statement !=null)
            {
                statement.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        try {
            if(resultSet !=null)
            {
                resultSet.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args)
    {
        System.out.println(JDBCTools.getConnection());
    }
}
